#pragma once

#include <QByteArray>
#include <QFile>
#include <QFileInfo>
#include <QXmlStreamWriter>
#include <QCryptographicHash>

class SocketQueue : public QObject
{
public:
    SocketQueue() = default;

    virtual QByteArray data() { return ""; }
    virtual bool isVaild() { return false; }
    virtual bool isFinished() { return false; }
};

class SocketQueue_NormalMsg : public SocketQueue
{
public:
    explicit SocketQueue_NormalMsg(const QByteArray &array = "");

    void addData(const QByteArray &array);
    QByteArray data() override;
    bool isVaild() override;
    bool isFinished() override;

private:
    QByteArray mArray;
};

class SocketQueue_FileMsg : public SocketQueue
{
    Q_OBJECT
public:
    explicit SocketQueue_FileMsg(const QString &filePath, const QString &remotePath, const QString *serverDir = nullptr);
    ~SocketQueue_FileMsg() override;

    qint64 size() { return mSize; }

    QByteArray data() override;
    bool isVaild() override;
    bool isFinished() override;

signals:
    void progress(qint64 value);
    void sendFileFinished();

private:
    QCryptographicHash mChecksum;
    QString mRemotePath;
    const QString *mServerDir;
    QFile mFile;
    qint64 mSize, mRead = 0;
    qint64 mPayloadSize = 65536 - 8;
    bool mFinished = false;
};
